<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *养殖管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$manage_op=array('confirm','cancel','agree','disagree');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择订单！','error');
	}
}
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'认领列表'),
);
$return['status']=$this->gdopt_status;
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['name'])){
		$params['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('id','number','uniacid','guoshu_id','mid','order_id','stage','feeding','water','status','shoutype','shoukg','shoufee','createtime');
	$list=pdo_getslice('jy_farmer_gdopt',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$animal=pdo_get('jy_farmer_guoshu',array('id'=>$item['guoshu_id'],'uniacid'=>$_SESSION['uniacid']),array('classify_id','stage','image','title','growtime','shouyue','shoukg','shoufee'));
			$item['growtime']=$animal['growtime'];
			$item['shouyue']=$animal['shouyue'];
			$item['shoukg2']=$animal['shoukg'];
			$item['shoufee2']=$animal['shoufee'];
			$item['aclassify_title']=pdo_getcolumn('jy_farmer_gclassify',array('id'=>$animal['classify_id'],'uniacid'=>$_SESSION['uniacid']),'title');
			$item['animal_title']=$animal['title'];
			$item['createtime']=date('Y-m-d h:i',$item['createtime']);
			$item['member']=cfc('core')->member_show($item['mid']);
			$stage=$animal['stage']?json_decode($animal['stage'],true):array();
			$item['stage']=$stage[$item['stage']]['stage_name'];
			$item['order']=pdo_get('jy_farmer_order',array('id'=>$item['order_id'],'uniacid'=>$_SESSION['uniacid']),array('username','total'));
			if($item['number']<10){
				$item['number']='000'.$item['number'];
			}elseif($item['number']<100 && $item['number']>9){
				$item['number']='00'.$item['number'];
			}else{
				$item['number']='0'.$item['number'];
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：果树订单确认，工人手机端可确认接单，然后进入种植流程！','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'用户','type'=>'member'),
			array('name'=>'order.username','title'=>'用户姓名','type'=>'string'),
			array('name'=>'aclassify_title','title'=>'果树分类名称','type'=>'string'),
			array('name'=>'animal_title','title'=>'果树名称','type'=>'string'),
			array('name'=>'number','title'=>'编号','type'=>'string'),
			array('name'=>'stage','title'=>'生长状态','type'=>'string'),
			array('type'=>'radio','title'=>'预计收获月份','name'=>'shouyue','options'=>'months'),
			array('type'=>'unitstring','title'=>'预计经济收益','name'=>'shoufee2','unit'=>'元/棵','help'=>''),
			array('type'=>'unitstring','title'=>'预计实物收获','name'=>'shoukg2','unit'=>'KG/棵','help'=>''),
			array('type'=>'unitstring','title'=>'实际收获','name'=>'shoukg','unit'=>'KG','help'=>''),
			array('name'=>'createtime','title'=>'认领时间','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		),'action'=>array(
			array('type'=>'modal','op'=>'tixian','title'=>'审核打款','show'=>array('shoutype'=>5,'status'=>5)),
			array('type'=>'post','op'=>'check','title'=>'确认接单','show'=>array('status'=>0)),
		)),
		'search'=>array(
			array('name'=>'username','width'=>15,'title'=>'用户姓名','type'=>'string'),
		)
	);
	$return['months']=array(1=>'1月',2=>'2月',3=>'3月',4=>'4月',5=>'5月',6=>'6月',7=>'7月',8=>'8月',9=>'9月',10=>'10月',11=>'11月',12=>'12月');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='check'){
	if($_RQ['id']){
		pdo_update('jy_farmer_gdopt',array('status'=>1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		exi('接单成功！');
	}else{
		exi('该果树不存在，请重新选择','error');
	}
}
if($_RQ['op']=='tixian'){
	if($_RQ['postdata']){
		$post=get_postdata();
		cfc('core')->member_credit($post['mid'],'credit1',$post['shoufee'],true,'jy_farmer','收获兑换收益');
		pdo_update('jy_farmer_gdopt',array('status'=>6),array('uniacid'=>$_SESSION['uniacid'],'id'=>$post['id']));
		exi('提现到余额完成！','','list');
	}
	$item=pdo_get('jy_farmer_gdopt',array('id'=>intval($_RQ['id'])));
	if(!$item){
		exi('指定订单不存在！','error');
	}
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'提现到余额',
		'edit'=>array(
			array('type'=>'unitstring','title'=>'实际收获','name'=>'shoukg','unit'=>'KG','read'=>true),
			array('type'=>'unitstring','title'=>'申请兑换金额','name'=>'shoufee','unit'=>'元','read'=>true),
		),
	);
	exi($return);
}
